package edu.fudan.langlab.domain.task;

import java.util.Date;
import java.util.Iterator;

import edu.fudan.mylang.utils.DateUtil;
import static edu.fudan.mylang.utils.DateUtil.*;

public class DateRangeIterable implements Iterable<Date> {
	private Date from;
	private Date to;

	public static DateRangeIterable forRange(Date from, Date to){
		return new DateRangeIterable(from,to);
	}
	public static DateRangeIterable forRangeFromNextDay(Date from, Date to){
		return new DateRangeIterable(DateUtil.addDays(from,1),to);
	}
	
	public DateRangeIterable(Date from, Date to) {
		this.from = from;
		this.to = to;
	}

	public Iterator<Date> iterator() {
		return new Iterator<Date>() {
			Date nextDate = from;
			
			public Date next() {
				Date result = nextDate;
				nextDate = addDays(nextDate, 1);
				return result;
			}
			
			public boolean hasNext() {
				return nextDate.getTime() <= to.getTime();
			}

			public void remove() {
				// TODO Auto-generated method stub
				
			}
		};
	}

}
